﻿/********************************************************
 * Module Name    : Organization
 * Purpose        : To display details of current opened window
 * Created By     : Lakhwinder
 * Class Used     : WindowVO.cs
 * Chronological Development
 * Lakhwinder
  ******************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using VAdvantage.Model;
using System.Text;
using VAdvantage.Grids;
using System.IO;
using SLControls.Controls;



namespace VAdvantage.Framework
{
    public partial class Help : SilverlightDesktop.Controls.Form
    {
        
        GridWindow grdWindow=null;
    
           
        /// <summary>
        /// set help text to show
        /// </summary>
        /// <param name="obj">Window object</param>
 
       public Help(GridWindow obj)
       {
           grdWindow = obj;
           InitializeComponent();
           LayoutRoot.Background=new SolidColorBrush(DataBase.GlobalVariable.WINDOW_BACK_COLOR);
       }
      

        public void SetHelpText()
        {
            vlblWindowName.Content = grdWindow.GetName();
            vlbldescription.Content= grdWindow.GetDescription();
            vlblHelp.Text= grdWindow.GetHelp();
            for (int i = 0; i < grdWindow.GetTabCount(); i++)
            {
                TabItem tabItem = new TabItem();
                ScrollViewer scroll = new ScrollViewer();
                GridTab tab = grdWindow.GetTab(i);
                Grid tabGrid=new Grid();
                scroll.Content = tabGrid;
                tabItem.Content=scroll;
                tabcontrolTabs.Items.Add(tabItem);
                tabItem.Header=tab.GetName();
                VLabel vlbltabName = new VLabel();
                vlbltabName.Content = tab.GetName();
                VLabel vlbtabDesc = new VLabel();
                vlbtabDesc.Content = tab.GetDescription();
                VLabel vlbltabHelp = new VLabel();
                vlbltabHelp.Content= tab.GetHelp();
                RowDefinition tabrow = new RowDefinition();
                tabrow.Height = new GridLength(0, GridUnitType.Auto);
                Grid.SetRow(vlbltabName, i);
                Grid.SetColumn(vlbltabName, 0);
                Grid.SetRow(vlbtabDesc, i + 1);
                Grid.SetColumn(vlbtabDesc, 0);
                Grid.SetRow(vlbltabHelp, i + 2);
                Grid.SetColumn(vlbltabHelp, 0);
                tabGrid.RowDefinitions.Add (tabrow);
                for (int j = 0; j < tab.GetFieldCount(); j++)
                {
                    GridField objField = tab.GetField(j);
                    Grid fieldGrid = new Grid();
                    Border border = new Border();
                    border.Background = new SolidColorBrush(Color.FromArgb(15,0,0,0));
                    border.BorderThickness =new Thickness(1,1,0,2);
                    border.BorderBrush = new SolidColorBrush(Colors.Transparent);
                    border.Child = fieldGrid;
                    fieldGrid.Margin = new Thickness(1);
                    RowDefinition row1 = new RowDefinition();
                    row1.Height = new GridLength(0, GridUnitType.Auto);
                    fieldGrid.RowDefinitions.Add(row1);
                    RowDefinition row2 = new RowDefinition();
                    row2.Height = new GridLength(1, GridUnitType.Auto);
                    fieldGrid.RowDefinitions.Add(row2);
                    RowDefinition row3 = new RowDefinition();
                    row3.Height = new GridLength(2, GridUnitType.Auto);
                    fieldGrid.RowDefinitions.Add(row3);
                    VLabel vlblField = new VLabel();
                    vlblField.Foreground =  new SolidColorBrush(Colors.Red);
                    vlblField.IsRequired = true;
                    vlblField.Content = objField.GetHeader();
                    TextBlock vlblFlddesc = new TextBlock();
                    vlblFlddesc.TextWrapping =TextWrapping.Wrap;
                    vlblFlddesc.Text = objField.GetDescription();
                    TextBlock vlblFieldHelp = new TextBlock();
                    vlblFieldHelp.TextWrapping = TextWrapping.Wrap;
                    vlblFieldHelp.Text = objField.GetHelp();
                    Grid.SetRow(vlblField, 0);
                    Grid.SetColumn(vlblField, 0);
                    Grid.SetRow(vlblFlddesc,1);
                    Grid.SetColumn(vlblFlddesc, 0);
                    Grid.SetRow(vlblFieldHelp, 2);
                    Grid.SetColumn(vlblFieldHelp,0);
                    fieldGrid.Children.Add(vlblField);
                    fieldGrid.Children.Add(vlblFlddesc);
                    fieldGrid.Children.Add(vlblFieldHelp);
                    RowDefinition row = new RowDefinition();
                    row.Height = new GridLength(0, GridUnitType.Auto);
                    tabGrid.RowDefinitions.Add(row);
                    Grid.SetRow(border,j+4);
                    Grid.SetColumn(border, 0);
                    tabGrid.Children.Add(border);
                    
                }
            }
        }

        private void Help_ResizeEnd(object sender, EventArgs e)
        {
            //call function to set help text of current window
            SetHelpText();
        }

        private void Form_Loaded(object sender, RoutedEventArgs e)
        {
           // Application.Current.Host.Content.IsFullScreen = true;
            this.Height = App.Current.Host.Content.ActualHeight - 30;
            this.Width = App.Current.Host.Content.ActualWidth ;
            SetHelpText();        
        }

        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            Application.Current.Host.Content.IsFullScreen = true;
        }

        
    }
}
  
    


